{$header}
<div id="main" class="main" >
    <div class="content">
  <h3 class="heading">新增销售单 [ <a href="__URL__">返回列表</a> ] 批量导入产品</h3>
<div id="result" class="result none"></div>
<table>
<?php
      $sale = M('Sale')->getById($_REQUEST['id']);
      $new_sale_no = empty($sale['sale_no']) ? '': $sale['sale_no'].'B'.date("YmdH").'';
      $bu_no = M('Sale')->where('sale_no like "'.$sale['sale_no'].'B%"')->getField('sale_no');
?>
    <tr>
            <td class="tRight" >模板下载：</td>
            <td class="tLeft"  colspan="3">
                <a href="__PUBLIC__/Uploads/销售导入模板.xls"><i class="icon-download-alt"></i>销售导入模板</a>
            </td>
</tr>
<form name="form" action="" method="POST" enctype="multipart/form-data">
<tr>
    <td>上传文件：</td>
    <td colspan="3">
        <input id="fileToUpload" type="file" size="45" name="upload" class="input">
        <a class="btn btn-primary" onClick="return ajaxFileUpload();">批量导入</a>
    </td>
</tr>
</form>
</table>
<form class="form-horizontal well" method='post' id="form1" name="form1" action="__APP__/Sale/insert/">
<table cellpadding=3 cellspacing=3 >
<notempty name="bu_no">
<tr>
    <td><span class="label label-important">已补发单号:</td>
    <td>{$bu_no} 
<span class="label label-important">已有补发单号,请勿重复补发</span>  </td>
</tr>
</notempty>
<tr>
    <td class="tRight">销售单号：</td>
	<td class="tLeft" >
            <input  class="input-xlarge" name="sale_no" value="{$new_sale_no}">留空，则系统自动生成</td>
    <td>原单号：</td>
    <td>
        <input type="text" class = "span2" name= "mall_no">
        下单时间：<input type="text" class="span2" name="create_time" value="{:toDate(time())}" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})">
    </td>
</tr>
<!--
<tr>
    <td class="tRight" width="150px">按<b>条码</b>查询产品：</td>
	<td class="tLeft" >
            <input id="ptm" name="ptm_id" style="width:700px"></input>
            <br/><a class="btn btn-primary" href="javascript:void(0)" onclick="showdetail('ptm','sale');">添加产品</a>
        </td>
</tr>
<tr>
	<td class="tRight" >按<b>拼音首字母</b>查询产品：</td>
	<td class="tLeft" >
            <input id="ppy" name="ppy_id" style="width:700px"></input>
            <br/><a class="btn btn-primary" href="javascript:void(0)" onclick="showdetail('ppy','sale');">添加产品</a>
        </td>
</tr>
-->


<tr>
	<td class="tRight" >经办人：</td>
	<td>
            <select name="user_id">
                <volist name="users" id="us">
                <option value="{$key}" <eq name="_SESSION[C('USER_AUTH_KEY')]" value="$key">selected</eq> >{$us}</option>
                </volist>
            </select>
        </td>
        <td>客户(买家ID)</td>
        <td> <input type="hidden" name="warehouse_id" value="1">
            <input type="text" name="customer_name" value="{$sale.customer_name}">若是新客户，直接填写名称
        </td>
</tr>
    <tr>
        <td><code>状态：</code></td>
        <td>审核状态：<SELECT class="span2"   name="status">启用</option>
            <option value="0">待审核</option>
            </SELECT> 订单状态{:configList( C('orderstatus'),'','order_status','span2' )}
         </td>
        <td>快递费：</td><td><input type="text" name="logifee"></td>
    </tr>
    <tr>
        <td>支付方式：</td><td><input type="text" name="pay_method" value="{$sale.pay_method}"> </td>
        <td>订单来源：</td><td>{:modList('Order_source', $sale['order_source_id'],'span2','order_source_id' )}</td>
    </tr>
    <tr>
        <td><code>应付款：</code></td><td> <input id="" type="text" name="should_pay" /> </td>
        <td><code>实付款：</code></td><td> <input type="text" name="real_pay" value=""> </td>
    </tr>
    
     <tr><td colspan="4" class="heading h4 alert alert-info">收货信息</td> </tr>
     <tr> <td>收货人：</td><td>
        <input type="hidden" name="shipping_address_id" value="{$vo.shipping_address_id}" >
        <input type="text" name="shipping_name" value="{$sale.shipping_name}"> 
    </td>
         <td>手机</td><td> <input type="text" name="mobile" value="{$sale.mobile}"> </td>
        
    </tr>
    <tr>
       <td colspan="4">地址：
       省份<input class="span1" type="text" name="province" value="{$sale.province}" />
       城市<input class="span1" type="text" name="city" value="{$sale.city}" />
       区县<input class="span1" type="text" name="county" value="{$sale.county}" />
       <input type="text" class="input-xxlarge" name="address" value="{$sale.address}"> 
        电话: <input type="text" name="phone" value="{$sale.phone}"> </td>
    </tr>
    <tr><td colspan="4" class="heading h4 alert alert-info">其他信息</td> </tr>
    <tr> <td>发票抬头：</td><td><input type="text" name="invoice_title" value="{$sale.invoice_title}"> </td>
        <td>发票内容：</td><td><input type="text" name="invoice_content" value="{$sale.invoice_content}"> </td>
    </tr>
    <tr>
        <td>客户留言：</td><td><input type="text" class="input-xxlarge" name="customer_msg" value="{$sale.customer_msg}"> </td>
        <td>支付宝：</td><td><input type="text" class="input-xxlarge" name="alipay" value="{$sale.alipay}"></td>
     </tr>
<tr>
	<td class="tRight">备注：</td>
        <td class="tLeft" colspan="3"><textarea class="span12" name="remark" rows="2"></textarea>
        </td>
</tr>
<tr>
    <td class="tRight" >按<b>汉字</b>查询产品：</td>
    <td class="tLeft" colspan="3" >
            <div class="input-append">
                <input id="q" name="q" class="input-xxlarge search-query" placeholder="搜索"><input id="hz" name="hz_id" type="hidden"></input>
                <button class="btn" type="button" onclick="filter('sale')"><i class="icon-search"></i>搜索</button>
                <span class="help-inline alert">支持空格查询,如:名称 + 度数</span>
            </div>
        </td>
</tr>
<tr>
    <td class="tRight">选择的产品：</td>
        <td class="tLeft" colspan="3" >
            <table id="chosed_product" class="table table-bordered table-striped">
                <thead><tr><th>条码</th><th>名称</th><th>规格</th> <th>价格备注</th><th>售价</th><th>数量</th><th>单位</th><th>库存</th><th>生产批号</th><th>截止有效期</th><th>删除</th></tr></thead>
            </table>
        </td>
</tr>
<tr>
   <td>仓库</td>
   <td class="tLeft" colspan="3" >{:modList('Warehouse',1)} </td>
</tr>
<tr>
	<td></td>
	<td class="center" width="300">
	<button type="submit" class="btn btn-primary"><i class="icon-ok icon-white"></i> 保存</button>
	<a class="btn btn-primary offset1" href="__URL__"><i class="icon-arrow-left icon-white"></i>返回</a>
	</td><td></td>
</tr>
</table>
</form>
</div>
</div>
<include file="Public:footer" />
<link rel="stylesheet" type="text/css" href="__PUBLIC__/Js/easyui/themes/default/easyui.css">
<script type="text/javascript" src="__PUBLIC__/Js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Js/filter-product.js"></script>
<load href="__PUBLIC__/Js/My97DatePicker/WdatePicker.js" />
<script type="text/javascript" src="__PUBLIC__/Js/ajaxfileupload.js"></script>

<script type="text/javascript">
    function ajaxFileUpload()
    {
        $("#loading")
        .ajaxStart(function(){
            $(this).show();
        })
        .ajaxComplete(function(){
            $(this).hide();
        });

        $.ajaxFileUpload
        (
            {
                url:URL+'/import',
                secureuri:false,
                fileElementId:'fileToUpload',
                dataType: 'json',
                data:{name:'logan', id:'id'},
                success: function (data, status)
                {
                    if(typeof(data.error) != 'undefined')
                    {
                        if(data.error != '')
                        {
                            alert(data.error);
                        }else
                        {
                            var msg = URLdecode(data.msg);
                            $('#chosed_product').append(msg);
                        }
                    }
                },
                error: function (data, status, e)
                {
                    alert(e);
                }
            }
        )
        
        return false;

    }

function URLdecode(str) {
        var ret = "";
        for(var i=0;i<str.length;i++) {
                var chr = str.charAt(i);
                if(chr == "+") {
                        ret += " ";
                }else if(chr=="%") {
                        var asc = str.substring(i+1,i+3);
                        if(parseInt("0x"+asc)>0x7f) {
                                ret += decodeURI("%"+ str.substring(i+1,i+9));
                                i += 8;
                        }else {
                                ret += String.fromCharCode(parseInt("0x"+asc));
                                i += 2;
                        }
                }else {
                        ret += chr;
                }
        }
        return ret;
}
</script>
